xref: /expo/guides/Generating Jest Mocks.md (revision da751fd5)
1# Generating new Jest Mocks
2
3This document will guide you through the process of generating new Jest Mocks for `packages/jest-expo` module using `apps/jest-expo-mock-generator`.
4
5# **Why**
6
7We provide some mocks of our native methods which are generated by traversing all the modules and its methods and making a configuration of all those methods with the number of arguments etc.
8
9# **How**
10
111. In your terminal, go to `apps/jest-expo-mock-generator`
12  - run `yarn` to ensure the dependencies are installed
13  - run `expo start` to start the Expo server
14
152. Open the **Expo Go** project on `iOS` by opening `ios/Exponent.xcworkspace`
16  - run the project on a simulator or a device
17
183. Open `jest-expo-mock-generator` in the running **Expo Go** app
19
204. After the app is finished opening, in the terminal, where the Expo server is running, you should see a big chunk of text wrapped with
21
22    `------------------------------COPY THE TEXT BELOW------------------------------`
23
24    and
25
26    `------------------------------END OF TEXT TO COPY------------------------------`
27
28    lines. Select and copy the text from between those lines.
29
30https://user-images.githubusercontent.com/379606/120577838-b4964a80-c3d9-11eb-93db-aba3ea9eef41.mp4
31
325. Stop the Expo server running in `apps/jest-expo-mock-generator`, started in step 1.
33
346. Paste the copied text into `packages/jest-expo/src/preset/expoModules.js`.
35
367. In the terminal, go into `packages/jest-expo`.
37
388. Run `yarn prettier src/preset/expoModules.js --write`.
39
409. Commit the changes. Bonus points for not modifying mock values (like `deviceYearClass`), which will be different if you use a test device different than the one used before.
41